/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = '';
  
  checkConfig(config);
  @endpoint = getEndpoint('linkedmallretrieval', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model AISearchQuery {
  card?: string(name='card'),
  cardQuery?: string(name='cardQuery'),
  page?: int32(name='page'),
  query?: string(name='query'),
  searchEngine?: string(name='searchEngine'),
  searchPlan?: string(name='searchPlan'),
  sessionId?: string(name='sessionId'),
  timeRange?: string(name='timeRange'),
}

model AISearchResult {
  header?: EventHeader(name='header'),
  payload?: string(name='payload'),
  requestId?: string(name='requestId', example='3239281273464326823'),
}

model EventHeader {
  event?: string(name='event', example='on_common_search_stream'),
  eventId?: string(name='eventId', example='ff3de49-cedc-47ea-ba3c-8456acd345d8'),
  requestId?: string(name='requestId', example='55c2349-cedc-47ea-ba3c-8456acd6c7d8'),
  responseTime?: long(name='responseTime', example='1403'),
}

model GenericSearchResult {
  pageItems?: [
    ScorePageItem
  ](name='pageItems'),
  requestId?: string(name='requestId', example='123456'),
  searchInformation?: SearchInformation(name='searchInformation'),
  weiboItems?: [
    WeiboItem
  ](name='weiboItems'),
}

model IncludeImage {
  height?: int32(name='height', example='324'),
  imageLink?: string(name='imageLink', example='http://k.sinaimg.cn/n/sinakd20121/594/w2048h946/20240328/74cf-32c0d62e843df76567d760b4459d57c1.jpg/w700d1q75cms.jpg'),
  width?: int32(name='width', example='700'),
}

model ScorePageItem {
  cardType?: string(name='cardType', description='This parameter is required.', example='structure_web_info'),
  displayLink?: string(name='displayLink', description='This parameter is required.', example='baijiahao.baidu.com'),
  htmlSnippet?: string(name='htmlSnippet', description='This parameter is required.', example='100km/h-0制动能力上，仅有33.3m，不黑不吹，单看这个，<em>小米SU7</em>确实表现不错。而续航方面，101kWh电池容量，实现CLTC续航800km，还有现5分钟补能220km，15分钟补能510km的800V高压平台。而在...'),
  htmlTitle?: string(name='htmlTitle', description='This parameter is required.', example='<em>小米</em>SU7售价22.99万元起 高管亲自辟谣：发布前不会有<em>价格</em>-百家号'),
  images?: [
    IncludeImage
  ](name='images'),
  link?: string(name='link', description='This parameter is required.', example='https://baijiahao.baidu.com/s?id=1787881554557805096'),
  mainText?: string(name='mainText', example='昨天	，	小米	汽车	没有	发布	，	但	相关	的	信息	透露	的	差	不	多	了	。		
		在	发布	会	现场	，	雷军	直接	称	小米	S	U	7	对	标	特斯拉	保时捷	，	有	100	项	行业	领先	，	可见	“	遥遥	领先	”	已经	不再	是	华为	专利	了	？		
	
		而	在	介绍	技术	时	，	雷军	也	从	电机	、	电池	、	大	压铸	、	自动	驾驶	、	智能	座舱	等	五	大	方面	展开	，	充分	展示	了	小米	汽车	的	技术	以及	技术	储备	，		 		能	堆	的	料	，	全都	堆	上去	了	…	…		
		大家	比较	感	兴趣	的	性能	方面	，	2	.	78	s	的	0	-	100	km	/	h	加速	，	265	km	/	h	的	最高	时速'),
  mime?: string(name='mime', example='text/html'),
  pageMap?: map[string]string(name='pageMap'),
  publishTime?: long(name='publishTime', description='This parameter is required.', example='1704426524000'),
  score?: double(name='score', example='0.234325235'),
  title?: string(name='title', description='This parameter is required.', example='小米SU7售价22.99万元起 高管亲自辟谣：发布前不会有价格'),
}

model SearchInformation {
  searchTime?: long(name='searchTime'),
  total?: long(name='total'),
}

model WeiboItem {
  cardType?: string(name='cardType', description='This parameter is required.', example='weibo_strong'),
  homepageLink?: string(name='homepageLink', example='https://m.weibo.cn/u/7761793874?luicode=20000061&lfid=5024099350350075'),
  htmlSnippet?: string(name='htmlSnippet', description='This parameter is required.', example='【小调查：你会买<em>小米SU7</em>吗？】#小米SU7路测覆盖300多城市#4月17日，@小米汽车 发文称SU7道路测试覆盖全国300多个城市，涵盖极寒，极热天气，总里程数高达540万公里，目前仍在进行中。  网页链接'),
  images?: [ string ](name='images'),
  link?: string(name='link', description='This parameter is required.', example='https://m.weibo.cn/detail/5024099350350075?wm=90194_90009'),
  publishDisplayTime?: string(name='publishDisplayTime', description='This parameter is required.', example='1小时前'),
  username?: string(name='username', example='白鹿科技'),
}

model AISearchV2Request {
  query?: string(name='query', description='This parameter is required.'),
  sessionId?: string(name='sessionId', example='14199B5E-5906-52BD-800D-900268AEC9F6'),
  timeRange?: string(name='timeRange'),
}

model AISearchV2ResponseBody = {
  header?: {
    event?: string(name='event', example='on_common_search_stream'),
    eventId?: string(name='eventId', example='ff3de49-cedc-47ea-ba3c-8456acd345d8'),
    responseTime?: long(name='responseTime', example='1403'),
  }(name='header'),
  payload?: string(name='payload'),
  requestId?: string(name='requestId', example='D016A23D-738A-5209-A91A-6145845C5A23'),
}

model AISearchV2Response = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: AISearchV2ResponseBody(name='body'),
}

/**
 * @summary 提供通用检索与检索后处理的多阶段优化结果，为开放域QA提供信源
 *
 * @param request AISearchV2Request
 * @param headers map
 * @param runtime runtime options for this request RuntimeOptions
 * @return AISearchV2Response
 */
async function aISearchV2WithOptions(request: AISearchV2Request, headers: map[string]string, runtime: Util.RuntimeOptions): AISearchV2Response {
  Util.validateModel(request);
  var query : map[string]any = {};
  if (!Util.isUnset(request.query)) {
    query['query'] = request.query;
  }
  if (!Util.isUnset(request.sessionId)) {
    query['sessionId'] = request.sessionId;
  }
  if (!Util.isUnset(request.timeRange)) {
    query['timeRange'] = request.timeRange;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'AISearchV2',
    version = '2024-05-01',
    protocol = 'HTTPS',
    pathname = `/linked-retrieval/linked-retrieval-entry/v2/linkedRetrieval/commands/aiSearch`,
    method = 'GET',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @summary 提供通用检索与检索后处理的多阶段优化结果，为开放域QA提供信源
 *
 * @param request AISearchV2Request
 * @return AISearchV2Response
 */
async function aISearchV2(request: AISearchV2Request): AISearchV2Response {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return aISearchV2WithOptions(request, headers, runtime);
}

model GenericSearchRequest {
  query?: string(name='query'),
  timeRange?: string(name='timeRange', example='OneWeek'),
}

model GenericSearchResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: GenericSearchResult  
}

/**
 * @summary 通用搜索
 *
 * @param request GenericSearchRequest
 * @param headers map
 * @param runtime runtime options for this request RuntimeOptions
 * @return GenericSearchResponse
 */
async function genericSearchWithOptions(request: GenericSearchRequest, headers: map[string]string, runtime: Util.RuntimeOptions): GenericSearchResponse {
  Util.validateModel(request);
  var query : map[string]any = {};
  if (!Util.isUnset(request.query)) {
    query['query'] = request.query;
  }
  if (!Util.isUnset(request.timeRange)) {
    query['timeRange'] = request.timeRange;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'GenericSearch',
    version = '2024-05-01',
    protocol = 'HTTPS',
    pathname = `/linked-retrieval/linked-retrieval-entry/v2/linkedRetrieval/commands/genericSearch`,
    method = 'GET',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @summary 通用搜索
 *
 * @param request GenericSearchRequest
 * @return GenericSearchResponse
 */
async function genericSearch(request: GenericSearchRequest): GenericSearchResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return genericSearchWithOptions(request, headers, runtime);
}

